﻿using LY.Entity;
using LY.Entity.Entities;
using LY.Entity.PageSearch;
using LY.Entity.SearchEntity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LY.DataAccess.Repository
{
    public class DeptRepository : BaseRepository
    {
        public PagedList<S_Dept> QueryDeptList(PageView view)
        {
            string cols = @" [ID]
      ,[Name]
      ,[ShortName]
      ,[ParentID]
      ,[Path]
      ,[Sequence]
      ,[Code]
      ,[IsStop]
      ,[IsUnit]
      ,[Name]+'--'+[Path] as NewName "; 
            return base.PageGet<S_Dept>(view, cols,
                @"S_Dept "
                , ""
                , "Path  ",
                "");
        }

        public PagedList<S_Dept_EX> QueryDeptEXList(PageView view)
        {
            string cols = @" [ID]
      ,[Name]
      ,[ShortName]
      ,[ParentID]
      ,[Path]
      ,[Sequence]
      ,[Code]
      ,[IsStop]
      ,[IsUnit]
,[Name]+'--'+[Path] as NewName ";

            return base.PageGet<S_Dept_EX>(view, cols,
                @"S_Dept "
                , ""
                , "Path  ",
                "");
        }
        /// <summary>
        /// 删除会员投资信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int DeleteDept(int id)
        {
            string sql = " DELETE FROM [S_Dept] WHERE ID=@ID";
            return base.Excute(sql, new { ID = id });
        }

        /// <summary>
        /// 检索投资信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public S_Dept GetDept(int? id)
        {
            string sql = @" SELECT *
                       FROM [S_Dept] WHERE Id=@ID";
            return base.Get<S_Dept>(sql, new { ID = id });
        }

        public List<S_Dept> GetDeptList()
        {
            string sql = @" SELECT *
                       FROM [S_Dept] ";
            return base.Query<S_Dept>(sql, null);
        }

        //判断部门标号是否存在
        public int SelectCodeCount(int id, string code)
        {
            string sql = "select count(*) from S_Dept where Code=@Code and Id<>@Id";
            return base.Get<int>(sql, new {Id = id, Code = code });
        }
    }
}
